class Solution {
    // struct less_cmp
    // {
    //     bool operator() (pair<int, int> p1, pair<int, int> p2)
    //     {
    //         return p1.second < p2.second;
    //     }

    // };
public:
    vector<int> topKFrequent(vector<int>& nums, int k) {
        vector<int> ret;
        unordered_map<int, int> hash;
        for (auto i : nums)
            hash[i]++;
        
        auto less_cmp = [](pair<int, int> p1, pair<int, int> p2){
            return p1.second < p2.second;
        };

        priority_queue<pair<int, int>, vector<pair<int, int>>, decltype(less_cmp)> hop;
        for (auto it : hash)
            hop.push(it);

        while (k--)
        {
            ret.push_back(hop.top().first);
            hop.pop();
        }

        return ret;
        
    }
};